<?php

namespace app\common\model;

use app\common\model\BaseModel as BaseModel;
use ShidianUtil\Thinkphp\Facade\HumanizedTool;
use ShidianUtil\Utils\TimeUtil;

/**
 * Class RankBroadcast
 * @package app\common\model
 * @property int	$id
 * @property string	$type
 * @property int	$memberId
 * @property string	$title
 * @property string	$content
 * @property int	$updated
 * @property int	$created
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class RankBroadcast extends BaseModel
{
    const DONGTAI = 'DONGTAI';
    const QIANGDAN = 'QIANGDAN';
    const DINGDAN = 'DINGDAN';

    protected $name = 'RankBroadcast';

    // 设置json类型字段
    protected $json = ['content'];
    protected $jsonAssoc = true;

    // 律师
    public function lawyer()
    {
        return $this->hasOne(Member::class, 'id', 'memberId');
    }

    public function getTimeStrAttr($value, $data)
    {
        $now = time();
        $time = $data['created'] ?? $now;

        if($time > $now){
            $time = $now;
        }

        return HumanizedTool::time($time);
    }
    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'RankBroadcast表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'RankBroadcast表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中RankBroadcast的键');
    //    }
}
